package com.lg.base_common_library.utils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by ligang on 2017/10/8.
 * description：
 */

public class TimeUtils {

    public static String getDateFromSeconds(String paramString) {
        if (paramString == null) {
            return " ";
        }
        Date localDate = new Date();
        try {
            localDate.setTime(1000L * Long.parseLong(paramString));
            return new SimpleDateFormat("yyyy-MM-dd").format(localDate);
        } catch (NumberFormatException localNumberFormatException) {
            localNumberFormatException.printStackTrace();
        }
        return "Input string:" + paramString + "not correct,eg:2011-01-20";
    }

    public static String getTimeStr(long paramLong) {
        long l = System.currentTimeMillis() / 1000L - paramLong;
        String str = getDateFromSeconds(String.valueOf(paramLong));
        if (l == 0L) {
            return "1秒前";
        }
        if ((1L <= l) && (l < 60L)) {
            return l + "秒前";
        }
        if ((1L <= l / 60L) && (l / 60L < 60L)) {
            return l / 60L + "分钟前";
        }
        if ((1L <= l / 3600L) && (l / 3600L < 24L)) {
            return l / 3600L + "小时前";
        }
        if ((1L <= l / 86400L) && (l / 86400L < 7L)) {
            return l / 86400L + "天前";
        }
        if ((7L <= l / 86400L) && (l / 86400L < 30L)) {
            String[] arrayOfString = str.split("-");
            return arrayOfString[1] + "/" + arrayOfString[2];
        }
        return str;
    }
}
